package taskManagerIncrement2TEST;

import static org.junit.Assert.*;  

import javax.swing.JMenuItem;

import org.junit.Test;
import org.junit.Before;

import taskManagerSystem.ControllerSubsystem.Controller;
import taskManagerSystem.ModelSubsystem.Model;
import taskManagerSystem.ViewSubsystem.Table;
import taskManagerSystem.ViewSubsystem.View;
import taskManagerSystem.ModelSubsystem.Task;
import taskManagerSystem.ModelSubsystem.Person;
import taskManagerSystem.ViewSubsystem.TableMod;
import taskManagerSystem.ViewSubsystem.TaskView;
import taskManagerSystem.ControllerSubsystem.TaskTableListener;
import taskManagerSystem.ControllerSubsystem.WindowSaveOnExitListener;

public class ViewTEST1 {
	
	Model model;
	View view;
	Controller control;
	Task task;
	Table table;
	Person person;
	TableMod TableModel;
	TaskView taskview;
	TaskTableListener tLis;
	WindowSaveOnExitListener wLis;
	JMenuItem newMenuItem;
	JMenuItem loadMenuItem;
	JMenuItem saveMenuItem;
	JMenuItem newTaskMenuItem;
	JMenuItem delTaskMenuItem;
	JMenuItem exitMenuItem;
	
	String[] taskCols = {"ID", "Title", "Description", "Duration", "Deliverable", "Deadline", "Person"};
	Class<?>[] taskTypes = {Integer.class, String.class, String.class, Integer.class, String.class, String.class, String.class};
	String[] personCols = {"ID", "Name", "Total Hours", "Tasks"};
	Class<?>[] personTypes = {Integer.class, String.class, Integer.class, String.class};
	
	@Before
	@Test
	public void testView() {
		model = new Model();
		view = new View(model);
		//testing the View class constructor
		assertNotNull(view);
	}

	@Test
	public void testSetVisible() {
		view.setVisible(true);
		assertTrue(view.isVisible());
	}

	@Test
	public void testIsVisible() {
		view.setVisible(true);
		assertTrue(view.isVisible());
	}

	@Test
	public void testEmptyTaskTable() {
		table = new Table(taskCols, taskTypes);
		assertEquals(null, null);
	}

	@Test
	public void testEmptyPersonTable() {
		table = new Table(personCols, personTypes);
		assertEquals(null, null);
	}

	@Test
	public void testGetSelectedTaskID() {
		table = new Table(taskCols, taskTypes);
		String[] row = new String[7];
		row[0] = "01";
		row[1] = "Title";
		row[2] = "Description";
		row[3] = "Duration";
		row[4] = "Deliverable";
		row[5] = "Deadline";
		row[6] = "Person";
		table.addRow(row);
		assertEquals(01, Integer.parseInt((String) table.getValueAt(0, 0)));
	}

	@Test
	public void testGetSelectedRow() {
		table = new Table(taskCols, taskTypes);
		String[] row = new String[7];
		row[0] = "01";
		row[1] = "Title";
		row[2] = "Description";
		row[3] = "Duration";
		row[4] = "Deliverable";
		row[5] = "Deadline";
		row[6] = "Person";
		table.addRow(row);
		assertEquals(-1,table.getSelectedRow());
	}

	@Test
	public void testPopulateTaskTable() {
		table = new Table(taskCols, taskTypes);
		String[] row = new String[7];
		row[0] = "01";
		row[1] = "Title";
		row[2] = "Description";
		row[3] = "Duration";
		row[4] = "Deliverable";
		row[5] = "Deadline";
		row[6] = "Person";
		table.addRow(row);
		assertNotNull(table.getValueAt(0,0));
		assertNotNull(table.getValueAt(0,1));
		assertNotNull(table.getValueAt(0,2));
		assertNotNull(table.getValueAt(0,3));
		assertNotNull(table.getValueAt(0,4));
		assertNotNull(table.getValueAt(0,5));
		assertNotNull(table.getValueAt(0,6));
	}

	@Test
	public void testPopulatePersonTable() {
		table = new Table(personCols, personTypes);
		String[] row = new String[4];
		row[0] = "01";
		row[1] = "Name";
		row[2] = "Total Hours";
		row[3] = "Tasks";
		table.addRow(row);
		assertNotNull(table.getValueAt(0,0));
		assertNotNull(table.getValueAt(0,1));
		assertNotNull(table.getValueAt(0,2));
		assertNotNull(table.getValueAt(0,3));
	}

	@Test
	public void testAddActionListeners() {
		newMenuItem = new JMenuItem();
		assertNotNull(newMenuItem);
		loadMenuItem = new JMenuItem();
		assertNotNull(loadMenuItem);
		saveMenuItem = new JMenuItem();
		assertNotNull(saveMenuItem);
		newTaskMenuItem = new JMenuItem();
		assertNotNull(newTaskMenuItem);
		delTaskMenuItem = new JMenuItem();
		assertNotNull(delTaskMenuItem);
		exitMenuItem = new JMenuItem();
		assertNotNull(exitMenuItem);
	}

	@Test
	public void testAddTaskTableListener() {
		tLis = new TaskTableListener(model, view);
		assertNotNull(tLis);
	}

	@Test
	public void testAddWindowSaveOnExitListener() {
		wLis = new WindowSaveOnExitListener(model, view);
		assertNotNull(wLis);
	}

}
